﻿using System;

namespace Designpatterns
{
    /// <summary>
    /// 工厂模式
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {

            #region 简单的工厂模式   封装 -  继承 - 多态

            try
            {

                Console.WriteLine("请输入数字A!");
                string srtNumberA = Console.ReadLine();
                Console.WriteLine("请选择运算符号（+、-、*、/）");
                string strOperate = Console.ReadLine();
                Console.WriteLine("请输入数字B!");
                string srtNumberB = Console.ReadLine();
                string strResult = "";


                // 一
                //switch (strOperate)
                //{
                //    case "+":
                //        strResult = Convert.ToString(Convert.ToDouble(srtNumberA) + Convert.ToDouble(srtNumberB));
                //        break;

                //    case "-":
                //        strResult = Convert.ToString(Convert.ToDouble(srtNumberA) - Convert.ToDouble(srtNumberB));
                //        break;
                //    case "*":
                //        strResult = Convert.ToString(Convert.ToDouble(srtNumberA) * Convert.ToDouble(srtNumberB));
                //        break;
                //    case "/":
                //        strResult = Convert.ToString(Convert.ToDouble(srtNumberA) / Convert.ToDouble(srtNumberB));
                //        break;

                //    default:
                //        break;
                //}
                //二
                //strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(srtNumberA), Convert.ToDouble(srtNumberB), strOperate));

                //三

                Operation operation;
                operation = OpeerationFactory.createOperate(strOperate);
                operation.NumebrA = 1;
                operation.NumebrB = 2;
                strResult = operation.GetResult().ToString();

                Console.WriteLine("结果是：" + strResult);
                Console.WriteLine();

            }
            catch (Exception ex)
            {

                Console.WriteLine("您的输入有错：" + ex.Message);

            }

            #endregion





        }
    }
}
